package com.aaa.sbm.controller;

import com.aaa.sbm.entity.Category;
import com.aaa.sbm.service.CategoryService;
import com.aaa.sbm.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@Controller
@RequestMapping("category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    
    @GetMapping("")
    public String index() {
        return "html/category";
    }
    
    @PostMapping("add")
    @ResponseBody
    public Result add(@RequestBody Category category) {
        log.info("添加类别，参数：{}", category);
        return categoryService.addCategory(category);
    }
    
    @PostMapping("update")
    @ResponseBody
    public Result update(@RequestBody Category category) {
        log.info("更新类别，参数：{}", category);
        return categoryService.updateCategory(category);
    }
    
    @GetMapping("delete/{id}")
    @ResponseBody
    public Result delete(@PathVariable Long id) {
        log.info("删除类别，ID：{}", id);
        return categoryService.deleteCategory(id);
    }
    
    @GetMapping("get/{id}")
    @ResponseBody
    public Result get(@PathVariable Long id) {
        return categoryService.getCategory(id);
    }
    
    @GetMapping("list")
    @ResponseBody
    public Result list() {
        return categoryService.getAllCategories();
    }
} 